//验证码按钮效果
var btnCode = document.getElementById('btnCode');
var countdown;

function disableButton() {
    var email = $('#email').val();

    $.get('logonServlet',{email:email}).then(function (){

        btnCode.disabled = true; // 禁用按钮
        btnCode.style.cursor = 'not-allowed'; // 设置鼠标样式

        countdown = 60; // 设置倒计时初始值

        updateButtonText(); // 更新按钮文本

        var timer = setInterval(function() {
            countdown--;

            if (countdown === 0) {
                clearInterval(timer);
                enableButton(); // 启用按钮
            } else {
                updateButtonText(); // 更新按钮文本
            }
        }, 1000);
    });
}

var enableButton = function() {
    btnCode.disabled = false; // 启用按钮
    btnCode.style.cursor = 'pointer'; // 恢复鼠标样式
    // 恢复按钮文本为原始内容
    btnCode.textContent = '验证码';
};

var updateButtonText = function() {
    // 更新按钮文本为倒计时格式
    btnCode.textContent = '验证码（' + countdown + '秒）';
};


//检测两次密码输入是否相同
// JavaScript 代码
var upwdInput = document.getElementById('upwd');
var upwd2Input = document.getElementById('upwd2');

var checkPasswordMatch = function() {
    var password = upwdInput.value;
    var confirm = upwd2Input.value;

    if (password != confirm) {
        // 两次密码不一致，显示错误消息
        alert('两次密码不一致，请重新输入！');
    }

    var Code = $('.Code').val();
    var uname = $('input[name=uname]').val();
    var upwd = $('#upwd').val();
    var email = $('#email').val(); //获取email的值

    $.post('logonServlet',{Code:Code,uname:uname,upwd:upwd, email:email},function(response){
        console.log(response);
        response = response.trim();
        if(response === "该邮箱已被注册"){
            alert("该邮箱已被注册");
        } else if(response === "验证码错误"){
            alert("验证码错误");
        }else if(response === "ok了兄弟们"){
            $('#qhuanann').trigger('click');
        }
    },'text');
};